package com.erp.common.web;

import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.erp.app.common.ProjectConstants;
import com.erp.framework.controller.action.SimpleUserStyleAction;

public class RemarkTextAction extends SimpleUserStyleAction {

    private static final String STATUS_P_SET = "pSet";

    protected String getModuleName(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response){
        return "";
    }
    
    public ActionForward otherExecute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response) throws ServletException {
        HttpSession session = request.getSession(false);
        ActionErrors errors = new ActionErrors();
        

        RemarkTextForm form = (RemarkTextForm) formIn;
        String action = form.getPageEvent();
        action = (action == null) ? "" : action.trim();
        ActionForward actionForward = new ActionForward(mapping.getInput());

        boolean handled = false;
        
        HashMap params = (HashMap) session.getAttribute(ProjectConstants.SESSION_REMARK_TEXT_PARAMETERS);
        session.removeAttribute(ProjectConstants.SESSION_REMARK_TEXT_PARAMETERS);
        if (params != null) {
            form.setParams(params);
            form.setRemarkColumnName((String) params.get(ProjectConstants.SESSION_EDIT_COLUMN_NAME));
            form.setRemarkText((String) params.get(ProjectConstants.SESSION_EDIT_VALUE));
            setHandled(request);
        }

        if (!isHandled(request) && action.equalsIgnoreCase("ok")) {
            HashMap params2 = form.getParams();
            String sessionValueName = (String) params2.get(ProjectConstants.SESSION_SESSION_VALUE);
            params2.put(ProjectConstants.SESSION_EDIT_VALUE, form.getRemarkText());
            session.setAttribute(sessionValueName, STATUS_P_SET);
            session.setAttribute(ProjectConstants.SESSION_REMARK_TEXT_PARAMETERS, params2);
            setHandled(request);
        }

        saveErrors(request, errors);
        return actionForward;
    }

}
